package homework.five.S_5_1;
import java.util.*;

public class TestList {
    private Map<String, Emp> empMap = new HashMap<>();

    // 添加员工
    public void addEmp(Emp emp) {
        if (empMap.containsKey(emp.getNumber())) {
            System.out.println("员工编号已存在，添加失败");
            return;
        }
        empMap.put(emp.getNumber(), emp);
        System.out.println("员工添加成功: " + emp);
    }

    public void findAllEmp() {
        if (empMap.isEmpty()) {
            System.out.println("当前没有员工信息");
            return;
        }
        System.out.println("===== 所有员工信息 =====");
        for (Emp emp : empMap.values()) {
            System.out.println(emp);
        }
    }

    public void findEmpByName(String ename) {
        boolean found = false;
        for (Emp emp : empMap.values()) {
            if (ename.equals(emp.getName())) {
                System.out.println("查询结果: " + emp);
                found = true;
            }
        }
        if (!found) System.out.println("未找到姓名为 " + ename + " 的员工");
    }

    public void deleteEmpByNumber(String number) {
        if (empMap.containsKey(number)) {
            Emp removedEmp = empMap.remove(number);
            System.out.println("已删除员工: " + removedEmp);
        } else {
            System.out.println("未找到编号为 " + number + " 的员工");
        }
    }

    public void findEmpByNumber(String number) {
        Emp emp = empMap.get(number);
        if (emp != null) {
            System.out.println("查询结果: " + emp);
        } else {
            System.out.println("未找到编号为 " + number + " 的员工");
        }
    }

    public void updateEmpAge(String number, int newAge) {
        if (empMap.containsKey(number)) {
            Emp emp = empMap.get(number);
            emp.setAge(newAge);
            System.out.println("员工年龄已更新: " + emp);
        } else {
            System.out.println("未找到编号为 " + number + " 的员工");
        }
    }


}